Convert jpg Byte[] to Texture2D

Posted by Damien Sawyer on Stack Overflow See other posts from Stack Overflow or by Damien Sawyer
Published on 2012-03-31T23:27:41Z Indexed on 2012/03/31 23:28 UTC
Read the original article Hit count: 236

Filed under:
|

I need to import jpeg images into a WP7/XNA app with associated metadata. The program which manages these images exports to an XML file with an encoded byte[] of the jpg files.

I've written a custom importer/processor which successfully imports the reserialized objects into my XNA project.

My question is, given the byte[] of the jpg, what is the best way to convert it back to Texture2D.

// 'Standard' method for importing image
Texture2D texture1 = Content.Load<Texture2D>("artwork"); // Uses the standard Content processor "Texture - XNA Framework" to import an image.

// 'Custom' method
var myCustomObject = Content.Load<CompiledBNBImage>("gamedata"); // Uses my custom content Processor to return POCO "CompiledBNBImage"
byte[] myJPEGByteArray = myCustomObject.Image; // byte[] of jpeg
Texture2D texture2 = ???? // What is the best way to convert myJPEGByteArray to a Texture2D?

Thanks very much for your help. :-)

DS

© Stack Overflow or respective owner

Related posts about XNA

Related posts about texture2d